Generating correlations in R
# ENMTools (standalone) doesn't seem to correctly calculate correlations, so this stage is done in R

# JUST USE RASTER. If any other libraries are loaded, it appears to interfere with the calculations for some reason
library(raster)


# Read in all the *.asc files
list_file <- list.files ("D:/Ornithodorus/ASC/top", pattern = "*.asc", full.names = T) 
ac <- stack(list_file)
ac

ac.brick <- brick(ac)
ac.brick
ac.brick[ac.brick < -100] <- NA
ac.brick

rc2.corr = layerStats(ac.brick, 'pearson', na.rm = TRUE)
rc2.corr
setwd("D:/Ornithodoros/CSV")
write.csv(rc2.corr, "O_turicata_corr.csv")
